{include file="include/top"}
<style>
    td,.layui-table th{
        text-align: center;!important;
    }
    .layui-col-md12{
        display: flex;
    }
</style>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">广告管理</a>
            <a>
              <cite>轮播列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card" style="width: 100%;">
                <div class="layui-card-body ">
                    <div class="layui-row">
                        <form class="layui-form layui-col-md12 x-so" action="{:url('Adver/shuffList')}" method="get">
                            <div style="margin: 10px 10px 10px 0px;width: 120px;">
                                <select name="city" lay-verify="required">
                                    <option value="ae_name">广告标题</option>
                                </select>
                            </div>
                            <input type="text" name="key"  placeholder="请输入搜索内容" autocomplete="off" class="layui-input" style="width: 15%;margin: 10px 10px 10px 0px"   >
                            <input class="layui-btn" name="sub" type="submit" value="搜索" style="margin: 10px 10px 10px 0px">
                        </form>
                    </div>
                    <xblock>
                        <button class="layui-btn" onclick="edit()"><i class="layui-icon"></i>添加</button>
                    </xblock>
                    <table class="layui-table layui-form" >
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>广告位置</th>
                            <th>广告标题</th>
                            <th>广告图片</th>
                            <th>广告链接</th>
                            <th>是否显示</th>
                            <th>排序</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="x-img">
                        {volist name="list" id="data"}
                        <tr>
                            <td>{$key+1}</td>
                            <td>首页轮播</td>
                            <td>{$data.ae_name}</td>
                            <td><img src="{$data.ae_img}"></td>
                            <td>{$data.ae_href}</td>
                            {if $data.ae_top == 1}
                            <td  onclick="member_stop(this,'adver','ae_id','{$data.ae_id}','ae_top',0,'隐藏')">
                                <input type="checkbox" name="switch"  lay-text="显示|隐藏"  checked="" lay-skin="switch">
                            </td>
                            {else}
                            <td  onclick="member_stop(this,'adver','ae_id','{$data.ae_id}','ae_top',1,'显示')">
                                <input type="checkbox" name="switch"  lay-text="显示|隐藏" lay-skin="switch">
                            </td>
                            {/if}
                            <td>{$data.ae_sort}</td>
                            <td>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="edit('{$data.ae_id}')">
                                    <i class="layui-icon">&#xe642;</i>
                                </button>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="member_stop(this,'adver','ae_id','{$data.ae_id}','ae_state',2,'删除')">
                                    <i class="layui-icon">&#xe640;</i>
                                </button>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        {$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });

        layer.ready(function(){ //为了layer.ext.js加载完毕再执行
            layer.photos({
                photos: '#x-img'
                ,shift: 5 //0-6的选择，指定弹出图片动画类型，默认随机
            });
        });
    });
    //添加查看弹框
    function edit(id = '')
    {
        if(id==''){
            var url = '{:url("Adver/shuffAddEdit")}';
            var desc = '添加';
            var arr = ['80%','80%'];
        }else{
            var url = '{:url("Adver/shuffAddEdit",["id"=>"getId"])}';
            url = url.replace('getId',id);
            var desc = '编辑';
            var arr = ['80%','80%'];
        }
        var loading =  layer.load(0, {shade: false});
        layer.open({
            type: 2,
            title:desc,
            area: arr,
            content: url
        });
        layer.close(loading);
    }
    /*显示隐藏*/
    function member_stop(obj,table,id,where,field,state,title){
        $.ajax({
            type: 'POST',
            url: '{:url("index/updateStatus")}',
            dataType: 'json',
            data : {table:table,id:id,where:where,field:field,state:state},
            success: function(data){
                if(data.code>0){
                    layer.msg('已'+title,{icon:1,time:1000});
                    setTimeout(function () {
                        location.reload();
                    }, 1000);
                }else{
                    layer.msg(title+'失败',{icon:5,time:1000});
                }
            },
            error:function(data) {
                console.log(data.msg);
            },
        });
    }
</script>
</html>